<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>群发推送</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px; margin-left: 310px; margin-right: 310px">
		<legend>输出内容</legend>
	</fieldset>

	<form class="layui-form" action="" style="margin-left: 200px; margin-right: 310px">
		<div class="layui-form-item layui-form-text">
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" class="layui-textarea" rows="10" id="contentArea1"></textarea>
			</div>
		</div>
	</form>
	
	<form class="layui-form" action="" style="margin-left: 200px; margin-right: 310px">
		<div class="layui-form-item layui-form-text">
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" class="layui-textarea" rows="10" id="contentArea2"></textarea>
			</div>
		</div>
	</form>

	<form class="layui-form layui-form-pane" style="margin-left: 310px; margin-right: 310px" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">输入</label>
			<div class="layui-input-block">
				<input type="text" name="content" id="content" autocomplete="off" placeholder="请输入内容" class="layui-input">
			</div>
		</div>
	</form>
	<div class="layui-form-item" style="margin-left: 310px; margin-right: 310px">
		<button class="layui-btn" onclick="sendMsg()">发送</button>
	</div>

	<script src="/js/jquery.min.js" ></script>
	<script src="/layui/layui.js" charset="utf-8"></script>
	<script>
		var websocket1 = new WebSocket("ws://127.0.0.1:8901/groupSocket");
		var websocket2 = new WebSocket("ws://127.0.0.1:8901/groupSocket");
		//第一个WebSocket打开
		websocket1.onopen = function(evt) {
			$('#contentArea1').html("第一个WebSocket服务连接成功");
		};

		//第一个WebSocket推送
		websocket1.onmessage = function(evt) {
			var val = $('#contentArea1').val() + "&#10;";
			$('#contentArea1').html(val + evt.data);
		};

		//第一个WebSocket关闭
		websocket1.onclose = function(evt) {
			$('#contentArea1').html("第一个WebSocket服务关闭成功");
		};
		
		//第二个WebSocket打开
		websocket2.onopen = function(evt) {
			$('#contentArea2').html("第二个WebSocket服务连接成功");
		};

		//第二个WebSocket推送
		websocket2.onmessage = function(evt) {
			var val = $('#contentArea2').val() + "&#10;";
			$('#contentArea2').html(val + evt.data);
		};

		//第二个WebSocket关闭
		websocket2.onclose = function(evt) {
			$('#contentArea2').html("第二个WebSocket服务关闭成功");
		};

		function sendMsg() {
			var text = $('#content').val();
			websocket1.send(text);
			websocket2.send(text);
		}
	</script>

</body>
</html>